<script setup lang="ts">
import { Handle, Position, useVueFlow } from '@vue-flow/core'
import { computed, ref, watch } from 'vue'

defineOptions({
  name: 'HttpInNode'
})

const props = defineProps<{
  id: string;
  data: {
    name: string;
    route?: string;
    enWS?: boolean;
    enInterrupt?: boolean;    
  };
  style?: Record<string, any>; // 添加 style 属性
}>()

const { updateNodeData } = useVueFlow()

const name = computed({
  get: () => props.data.name,
  set: (name) => updateNodeData(props.id, {...props.data, name: name }),
})

import useConnectionValid from './ts/connectionValid';
const { isValidConnection } = useConnectionValid();

// 节点属性
const route = ref(props.data.route || '');
const enWS = ref(props.data.enWS);
const enInterrupt = ref(props.data.enInterrupt);
watch(() => [route.value, enWS.value], ()=>{
  updateNodeData(props.id, {
    ...props.data,
    route: route.value,
    enWS: enWS.value
  })
})

</script>

<template>
    <div class="NodeName"> <input :id="`${id}-input`" v-model="name"  class="nodrag" /> </div>
    <div class="NodeContent">
      <Handle id="flow-next"  type="source" :class="['AgentFlowOutputHandle','top-0']"  :position="Position.Right"  title="FLow Next" >
        <span class="HandleRightSpan" :connectable="()=>{return isValidConnection(props.id,'flow-next', 'source')}">Flow Next</span> </Handle>
      <Handle id="query-msg"  type="source" :class="['AgentMsg','top-2']" :position="Position.Right"  title="Query"  :connectable="()=>{return isValidConnection(props.id,'query-msg', 'source')}">
        <span class="HandleRightSpan">Query</span></Handle>
      
      <Handle id="interrupt-flow-next"  type="source" :class="['AgentFlowOutputHandle','top-3']" :position="Position.Right"  title="Interrupt Flow" :connectable="()=>{return isValidConnection(props.id,'interrupt-flow-next', 'source')}"><span class="HandleRightSpan">Interrupt Flow</span></Handle>
      <div class="NodeData">
        <!-- 第一行：textinput -->
        <div class="input-row">
          <label for="textInput">Route:</label>
          <input
            id="textInput"
            type="text"
            v-model="route"
            placeholder="/your-route"
            :class="['text-input','nodrag']"
          />
        </div>

        <!-- 第二行：checkbox 1 -->
        <div class="checkbox-row">
          <label for="enWS">Enable WebSocket</label>
          <input
            id="enWS"
            type="checkbox"
            v-model="enWS"
            :class="['checkbox','nodrag']"
          />
        </div>

        <!-- 第三行：checkbox 2 -->
        <div class="checkbox-row">
          <label for="enInterrupt">Enable Interrupt</label>
          <input
            id="enInterrupt"
            type="checkbox" 
            v-model="enInterrupt"
            :class="['checkbox','nodrag']"
          />
        </div>
      </div>
    </div>
</template>

